import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Teacher } from '../../teacher/entities/teacher.entity';

@Entity('course')
export class Course {
    @PrimaryGeneratedColumn()
    cno: number;

    @Column({ name: 'cname', type: 'varchar', length: 50 })
    cname: string;

    @Column({ name: 'cdept', type: 'varchar', length: 50 })
    cdept: string;

    @Column({ 
        name: 'credit', 
        type: 'int', 
        default: 2 
    })
    credit: number;

    // 修正为正确的外键关联
    @ManyToOne(() => Teacher)
    @JoinColumn({ name: 'tno' }) // 明确指定外键列名
    teacher: Teacher;
}